home *** CD-ROM | disk | FTP | other *** search
- /*
- *=============================================================================
- * tSippMisc.c
- *-----------------------------------------------------------------------------
- * Miscellaneous commands.
- *-----------------------------------------------------------------------------
- * Copyright 1992 Mark Diekhans
- * Permission to use, copy, modify, and distribute this software and its
- * documentation for any purpose and without fee is hereby granted, provided
- * that the above copyright notice appear in all copies. Mark Diekhans makes
- * no representations about the suitability of this software for any purpose.
- * It is provided "as is" without express or implied warranty.
- *-----------------------------------------------------------------------------
- * $Id: tSippMisc.c,v 2.0 1992/11/02 03:56:23 markd Rel $
- *============================================================================
- */
-
- #include "tSippInt.h"
- #include "patchlevel.h"
-
- /*
- * Version string containing full version (SIPP version, TSIPP suffix and maybe
- * patchlevel.
- */
- char *TSIPP_VERSION;
-
- /*
- * Implied column 3 of the Transf_mat.
- */
- static double matrixCol3 [] = {0.0, 0.0, 0.0, 1.0};
-
- /*=============================================================================
- * SippMkVector --
- * Implements the command:
- * SippMkVector {pt0_x pt0_y pt0_z} {pt1_x pt1_y pt1_z}
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippMkVector (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Vector point0, point1, vector;
-
- if (argc != 3) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " {pt0_x pt0_y pt0_z} {pt1_x pt1_y pt1_z}",
- (char *) NULL);
- return TCL_ERROR;
- }
-
- if (!TSippConvertVertex (tSippGlobPtr, argv [1], &point0))
- return TCL_ERROR;
- if (!TSippConvertVertex (tSippGlobPtr, argv [2], &point1))
- return TCL_ERROR;
-
- vector.x = point1.x - point0.x;
- vector.y = point1.y - point0.y;
- vector.z = point1.z - point0.z;
- sprintf (tSippGlobPtr->interp->result, "%g %g %g",
- vector.x, vector.y, vector.z);
- return TCL_OK;
-
- } /* SippMkVector */
-
- /*=============================================================================
- * SippMatMult --
- * Implements the command:
- * SippMatMult matrix1 matrix2
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippMatMult (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Transf_mat matrix1, matrix2, resultMat;
- int row, col;
-
- if (argc != 3) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " matrix1 matrix2", (char *) NULL);
- return TCL_ERROR;
- }
- if (!TSippConvertMatrix (tSippGlobPtr, argv [1], &matrix1))
- return TCL_ERROR;
- if (!TSippConvertMatrix (tSippGlobPtr, argv [2], &matrix2))
- return TCL_ERROR;
-
- for (row=0; row <= 3; row++)
- for (col=0; col <= 2; col++)
- resultMat.mat [row][col] =
- matrix1.mat [row][0] * matrix2.mat [0][col] +
- matrix1.mat [row][1] * matrix2.mat [1][col] +
- matrix1.mat [row][2] * matrix2.mat [2][col] +
- matrixCol3 [row] * matrix2.mat [3][col];
-
- Tcl_SetResult (interp, TSippFormatMatrix (&resultMat), TCL_DYNAMIC);
- return TCL_OK;
-
- } /* SippMatMult */
-
- /*=============================================================================
- * SippShowBackFaces --
- * Implements the command:
- * SippShowBackFaces [flag]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippShowBackFaces (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- int flag;
-
- if (argc > 2) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " [flag]", (char *) NULL);
- return TCL_ERROR;
- }
- if (argc == 1) {
- if (tSippGlobPtr->showBackFaces)
- interp->result = "1";
- else
- interp->result = "0";
- } else {
- if (Tcl_GetBoolean (interp, argv [1], &flag) != TCL_OK)
- return TCL_ERROR;
- tSippGlobPtr->showBackFaces = flag;
- sipp_show_backfaces (flag);
- }
- return TCL_OK;
-
- } /* SippShowBackFaces */
-
- /*=============================================================================
- * SippBackground --
- * Implements the command:
- * SippBackground [color]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippBackground (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Color color;
-
- if (argc > 2) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " [color]", (char *) NULL);
- return TCL_ERROR;
- }
- if (argc == 1) {
- sprintf (interp->result, "%g %g %g",
- tSippGlobPtr->backgroundColor.red,
- tSippGlobPtr->backgroundColor.grn,
- tSippGlobPtr->backgroundColor.blu);
- } else {
- if (!TSippConvertColor (tSippGlobPtr, argv [1], &color))
- return TCL_ERROR;
- sipp_background (color.red, color.grn, color.blu);
- tSippGlobPtr->backgroundColor = color;
- }
- return TCL_OK;
-
- } /* SippBackground */
-
- /*=============================================================================
- * SippLineColor --
- * Implements the command:
- * SippLineColor [color]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippLineColor (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- Color color;
-
- if (argc > 2) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " [color]", (char *) NULL);
- return TCL_ERROR;
- }
- if (argc == 1) {
- sprintf (interp->result, "%g %g %g",
- tSippGlobPtr->lineColor.red,
- tSippGlobPtr->lineColor.grn,
- tSippGlobPtr->lineColor.blu);
- } else {
- if (!TSippConvertColor (tSippGlobPtr, argv [1], &color))
- return TCL_ERROR;
- tSippGlobPtr->lineColor = color;
- }
- return TCL_OK;
-
- } /* SippLineColor */
-
- /*=============================================================================
- * SippShadows --
- * Implements the command:
- * SippShadows flag [size]
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippShadows (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
- int flag;
- unsigned size;
-
- if ((argc < 2) || (argc > 3)) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " flag [size]", (char *) NULL);
- return TCL_ERROR;
- }
- if (Tcl_GetBoolean (interp, argv [1], &flag) != TCL_OK)
- return TCL_ERROR;
- if (flag) {
- if (argc != 3) {
- Tcl_AppendResult (interp, "size argument must be specified when ",
- "enabling shadows", (char *) NULL);
- return TCL_ERROR;
- }
- if (!TSippConvertPosUnsigned (tSippGlobPtr, argv [2], &size))
- return TCL_ERROR;
- } else {
- if (argc != 2) {
- Tcl_AppendResult (interp, "size argument must be omitted when ",
- "disabling shadows", (char *) NULL);
- return TCL_ERROR;
- }
- size = 0;
- }
- sipp_shadows (flag, size);
- return TCL_OK;
-
- } /* SippShadows */
-
- /*=============================================================================
- * SippInfo --
- * Implements the command:
- * SippInfo attribute
- * Note:
- * This procedure has standard Tcl command calling sematics. ClientData
- * contains a pointer to the Tcl SIPP global structure.
- *-----------------------------------------------------------------------------
- */
- static int
- SippInfo (clientData, interp, argc, argv)
- char *clientData;
- Tcl_Interp *interp;
- int argc;
- char **argv;
- {
- tSippGlob_pt tSippGlobPtr = (tSippGlob_pt) clientData;
-
- if (argc != 2) {
- Tcl_AppendResult (interp, "wrong # args: ", argv [0],
- " attribute", (char *) NULL);
- return TCL_ERROR;
- }
- if (STREQU ("version", argv [1])) {
- interp->result = TSIPP_VERSION;
- return TCL_OK;
- }
- if (STREQU ("sippversion", argv [1])) {
- interp->result = SIPP_VERSION;
- return TCL_OK;
- }
- if (STREQU ("tsippversion", argv [1])) {
- interp->result = TSIPP_VERSION_SUFFIX;
- return TCL_OK;
- }
- if (STREQU ("tsipppatchlevel", argv [1])) {
- sprintf (interp->result, "%d", PATCHLEVEL);
- return TCL_OK;
- }
- if (STREQU ("rle", argv [1])) {
- #ifdef TSIPP_NO_RLE
- interp->result = "0";
- #else
- interp->result = "1";
- #endif
- return TCL_OK;
- }
-
- Tcl_AppendResult (interp, "expected an attribute of \"version\", ",
- "\"sippversion\", \"tsippversion\", ",
- "\"tsipppatchlevel\", or \"rle\", got \"",
- argv [1], "\"", (char *) NULL);
- return TCL_ERROR;
-
- } /* SippInfo */
-
- /*=============================================================================
- * TSippInitialize --
- * Initialize the Tcl/Sipp environment.
- * Parameters:
- * o interp (I) - Pointer to the Tcl interpreter.
- *-----------------------------------------------------------------------------
- */
- void
- TSippInitialize (interp)
- Tcl_Interp *interp;
- {
- static tSippTclCmdTbl_t cmdTable [] = {
- {"SippMkVector", SippMkVector},
- {"SippMatMult", SippMatMult},
- {"SippShowBackFaces", SippShowBackFaces},
- {"SippBackground", SippBackground},
- {"SippLineColor", SippLineColor},
- {"SippShadows", SippShadows},
- {"SippInfo", SippInfo},
- {NULL, NULL}
- };
- tSippGlob_pt tSippGlobPtr;
- char patchBuf [10];
-
- /*
- * Define strings to be returned by the infox command. Include patch
- * level if its not zero.
- */
-
- tclAppName = "tSIPP";
- tclAppLongname = "Tcl-SIPP";
- TSIPP_VERSION = ckalloc (strlen (SIPP_VERSION) +
- strlen (TSIPP_VERSION_SUFFIX) + 10);
- tclAppVersion = TSIPP_VERSION;
- strcpy (TSIPP_VERSION, SIPP_VERSION);
- strcat (TSIPP_VERSION, TSIPP_VERSION_SUFFIX);
-
- #if PATCHLEVEL
- sprintf (patchBuf, "-P%d", PATCHLEVEL);
- strcat (TSIPP_VERSION, patchBuf);
- #endif
-
- sipp_init ();
-
- tSippGlobPtr = (tSippGlob_pt) ckalloc (sizeof (tSippGlob_t));
-
- tSippGlobPtr->interp = interp;
- tSippGlobPtr->showBackFaces = FALSE;
-
- tSippGlobPtr->backgroundColor.red = 0.0;
- tSippGlobPtr->backgroundColor.grn = 0.0;
- tSippGlobPtr->backgroundColor.blu = 0.0;
-
- tSippGlobPtr->lineColor.red = 1.0;
- tSippGlobPtr->lineColor.grn = 1.0;
- tSippGlobPtr->lineColor.blu = 1.0;
-
- TSippInitCmds (tSippGlobPtr, cmdTable);
-
- TSippBezierInit (tSippGlobPtr);
- TSippShaderInit (tSippGlobPtr);
- TSippPolyInit (tSippGlobPtr);
- TSippObjectInit (tSippGlobPtr);
- TSippLightInit (tSippGlobPtr);
- TSippCameraInit (tSippGlobPtr);
- TSippPrimInit (tSippGlobPtr);
- TSippPPMInit (tSippGlobPtr);
- TSippRLEInit (tSippGlobPtr);
-
-
- } /* TSippInitialize */
-